package com.cln.oldtreewalker;

import junit.framework.TestCase;

public class TreeTest extends TestCase {
	ATraverser preOrderTraverserOld = new PreOrderTraverserOld();
	ITraverser inOrderTraverserOld = new InOrderTraverserOld();
	ITraverser postOrderTraverserOld = new PostOrderTraverserOld();

	public void testTreePreTraverse() {
		TreeNode a = new TreeNode("a");
		assertEquals("a", preOrderTraverserOld.doTraverse(a));
	}

	public void testABCPreOrderTraverse() {
		TreeNode a = new TreeNode("a");
		TreeNode b = new TreeNode("b");
		TreeNode c = new TreeNode("c");
		a.setLeftChild(b);
		a.setRightChild(c);
		assertEquals("abc", preOrderTraverserOld.doTraverse(a));
	}

	public void testABCDEPreOrderTraverse() {
		TreeNode a = new TreeNode("a");
		TreeNode b = new TreeNode("b");
		TreeNode c = new TreeNode("c");
		TreeNode d = new TreeNode("d");
		TreeNode e = new TreeNode("e");
		a.setLeftChild(b);
		a.setRightChild(c);
		b.setLeftChild(d);
		b.setRightChild(e);
		assertEquals("abdec", preOrderTraverserOld.doTraverse(a));
	}

	public void testABCDEFInOrderTraverse() {
		TreeNode a = new TreeNode("a");
		TreeNode b = new TreeNode("b");
		TreeNode c = new TreeNode("c");
		TreeNode d = new TreeNode("d");
		TreeNode e = new TreeNode("e");
		TreeNode f = new TreeNode("f");
		a.setLeftChild(b);
		a.setRightChild(c);
		b.setLeftChild(d);
		b.setRightChild(e);
		e.setLeftChild(f);

		assertEquals("dbfeac", inOrderTraverserOld.doTraverse(a));
	}

	public void testABCDEF2InOrderTraverse() {
		TreeNode a = new TreeNode("a");
		TreeNode b = new TreeNode("b");
		TreeNode c = new TreeNode("c");
		TreeNode d = new TreeNode("d");
		TreeNode e = new TreeNode("e");
		TreeNode f = new TreeNode("f");
		a.setLeftChild(b);
		a.setRightChild(c);
		b.setLeftChild(d);
		b.setRightChild(e);
		e.setRightChild(f);
		assertEquals("dbefac", inOrderTraverserOld.doTraverse(a));
	}

	public void testABCDEFPostOrderTraverse() {
		TreeNode a = new TreeNode("a");
		TreeNode b = new TreeNode("b");
		TreeNode c = new TreeNode("c");
		TreeNode d = new TreeNode("d");
		TreeNode e = new TreeNode("e");
		TreeNode f = new TreeNode("f");
		a.setLeftChild(b);
		a.setRightChild(c);
		b.setLeftChild(d);
		b.setRightChild(e);
		e.setLeftChild(f);
		assertEquals("dfebca", postOrderTraverserOld.doTraverse(a));
	}

	public void testABCDEF2PostOrderTraverse() {
		TreeNode a = new TreeNode("a");
		TreeNode b = new TreeNode("b");
		TreeNode c = new TreeNode("c");
		TreeNode d = new TreeNode("d");
		TreeNode e = new TreeNode("e");
		TreeNode f = new TreeNode("f");
		a.setLeftChild(b);
		a.setRightChild(c);
		b.setLeftChild(d);
		b.setRightChild(e);
		e.setRightChild(f);
		assertEquals("dfebca", postOrderTraverserOld.doTraverse(a));
	}

}
